//
//  ProfileTableViewController.m
//  BaiTuan
//
//  Created by mycomputer on 15/12/25.
//  Copyright © 2015年 YR. All rights reserved.
//

#import "ProfileTableViewController.h"
#import "PushViewController.h"
#import "Common.h"
@interface ProfileTableViewController ()
@property (weak, nonatomic) IBOutlet UIView *scellView;
@property (weak, nonatomic) IBOutlet UIView *cellView;
@property (weak, nonatomic) IBOutlet UITableViewCell *indentCell;
@property (weak, nonatomic) IBOutlet UITableViewCell *walletCell;
@property (weak, nonatomic) IBOutlet UITableViewCell *ticketCell;
@property (weak, nonatomic) IBOutlet UITableViewCell *integralCell;
@property (weak, nonatomic) IBOutlet UITableViewCell *recommendCell;
@property (weak, nonatomic) IBOutlet UITableViewCell *luckCell;

@end

@implementation ProfileTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.showsHorizontalScrollIndicator = NO;
    self.tableView.showsVerticalScrollIndicator = NO;
    self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
    
    [self _headView];
    [self _scellContrl];
    [self _cellContrl];
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
    [self.navigationController.navigationBar.subviews objectAtIndex:0].alpha = 0;
    
}
//实现头视图
- (void)_headView{

    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, -400, kScreenWidth, 490)];
    view.backgroundColor = [UIColor colorWithRed:0 green:193/255.0  blue:173/255.0 alpha:1];
    UIImageView *imgView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 410, 70, 70)];
    imgView.image = [UIImage imageNamed:@"userHead"];
    [view addSubview:imgView];
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(90, 430, 220, 20)];
    NSString *userName = @"tqH978879";
    label.text = userName;
    label.textColor = [UIColor whiteColor];
    label.font = [UIFont systemFontOfSize:20];
    [view addSubview:label];
    [self.view addSubview:view];
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    CGFloat offsetY =  scrollView.contentOffset.y;
        NSLog(@"%f", offsetY);
    if (offsetY > 0) {
        [self.navigationController.navigationBar.subviews objectAtIndex:0].alpha = 1;
        self.navigationController.navigationBar.barStyle = UIBarStyleDefault;
    }else{
        double volue;
        volue = (offsetY + 64)/64;
        [self.navigationController.navigationBar.subviews objectAtIndex:0].alpha =volue;
        if ( offsetY>= -25) {
            self.navigationController.navigationBar.barStyle = UIBarStyleDefault;
        }
        if (offsetY < -25) {
            self.navigationController.navigationBar.barStyle = UIBarStyleBlack;

        }
        
    }



}

- (void)_scellContrl{
    NSArray *names = @[@"美团券",@"评价",@"收藏"];
    CGFloat controlWidth = kScreenWidth/names.count;
    for (int i = 0; i < names.count; i++) {
        NSString *name = names[i];
        UIControl *control = [[UIControl alloc]initWithFrame:CGRectMake(controlWidth*i, 0, controlWidth,_scellView.frame.size.height)];
        [control addTarget:self action:@selector(spushView:) forControlEvents:UIControlEventTouchUpInside];
        UILabel *nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, controlWidth, _scellView.frame.size.height*0.6)];
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, _scellView.frame.size.height*0.6, controlWidth, _scellView.frame.size.height*0.4)];
        nameLabel.text = name;
        nameLabel.textAlignment = NSTextAlignmentCenter;
        nameLabel.textColor = [UIColor blackColor];
        label.text = @"0";
        label.textAlignment = NSTextAlignmentCenter;
        label.textColor = [UIColor darkGrayColor];
        label.font = [UIFont systemFontOfSize:14];
        control.tag = i;
        [control addSubview:nameLabel];
        [control addSubview:label];
        [_scellView addSubview:control];
        
    }
}


- (void)spushView:(UIControl *)control{
    if (control.tag == 0) {
        PushViewController *pviewController = [[PushViewController alloc] init];
        pviewController.hidesBottomBarWhenPushed = YES;
        pviewController.title = @"我的美团券";
        [self.navigationController pushViewController:pviewController animated:YES];
    }
    if (control.tag == 1) {
        PushViewController *conViewController = [[PushViewController alloc]init];
        conViewController.hidesBottomBarWhenPushed = YES;
        conViewController.title = @"我的评价";
        [self.navigationController pushViewController:conViewController animated:YES];
    }
    if (control.tag == 2) {
        PushViewController *talkViewController = [[PushViewController alloc]init];
        talkViewController.hidesBottomBarWhenPushed = YES;
        talkViewController.title = @"收藏夹";
        [self.navigationController pushViewController:talkViewController animated:YES];
    }
}
- (void)_cellContrl{
    NSArray *names = @[@"mine1@2x",@"mine2@2x",@"mine3@2x",@"mine4@2x"];
    NSArray *labelText = @[@"待付款",@"待使用",@"待评价",@"退款／售后"];
    CGFloat controlWidth = kScreenWidth/names.count;
    for (int i = 0; i < names.count; i++) {
        NSString *name = names[i];
        NSString *textL = labelText[i];
        UIControl *control = [[UIControl alloc]initWithFrame:CGRectMake(controlWidth*i, 0, controlWidth,_cellView.frame.size.height)];
        [control addTarget:self action:@selector(pushView:) forControlEvents:UIControlEventTouchUpInside];
        UIImageView *imv = [[UIImageView alloc]initWithFrame:CGRectMake(30, 10, 35,35)];
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 45, controlWidth, 20)];
        imv.image = [UIImage imageNamed:name];
        label.text = textL;
        label.textAlignment = NSTextAlignmentCenter;
        label.textColor = [UIColor darkGrayColor];
        label.font = [UIFont systemFontOfSize:14];
        control.tag = i;
        [control addSubview:imv];
        [control addSubview:label];
        [_cellView addSubview:control];
    }
}

- (void)pushView:(UIControl*) control{
    if (control.tag == 0) {
        PushViewController *pviewController = [[PushViewController alloc] init];
        pviewController.hidesBottomBarWhenPushed = YES;
        pviewController.title = @"待付款";
        [self.navigationController pushViewController:pviewController animated:YES];
    }
    if (control.tag == 1) {
        PushViewController *conViewController = [[PushViewController alloc]init];
        conViewController.hidesBottomBarWhenPushed = YES;
        conViewController.title = @"待使用";
        [self.navigationController pushViewController:conViewController animated:YES];
    }
    if (control.tag == 2) {
        PushViewController *talkViewController = [[PushViewController alloc]init];
        talkViewController.hidesBottomBarWhenPushed = YES;
        talkViewController.title = @"待评价";
        [self.navigationController pushViewController:talkViewController animated:YES];
    }
    if (control.tag == 3) {
        PushViewController *refundViewController = [[PushViewController alloc]init];
        refundViewController.hidesBottomBarWhenPushed = YES;
        refundViewController.title = @"退款／售后";
        [self.navigationController pushViewController:refundViewController animated:YES];
    }
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0  && indexPath.section == 1) {
        UITableViewController *_indent = [[UITableViewController alloc]init];
        _indent.title =@"我的订单";
        _indent.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:_indent animated:YES];
    }
    if (indexPath.row == 0  && indexPath.section == 2) {
        UITableViewController *_wallet = [[UITableViewController alloc]init];
        _wallet.title =@"美团钱包";
        _wallet.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:_wallet animated:YES];
    }
    if (indexPath.row == 1  && indexPath.section == 2) {
        UITableViewController *_ticket = [[UITableViewController alloc]init];
        _ticket.title =@"抵用券";
        _ticket.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:_ticket animated:YES];
    }
    if (indexPath.section == 3) {
        UIViewController *_integral = [[UIViewController alloc]init];
        _integral.title =@"积分商城";
        _integral.view.backgroundColor = [UIColor yellowColor];
        _integral.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:_integral animated:YES];
    }
    if (indexPath.section == 4) {
        UITableViewController *_recommend = [[UITableViewController alloc]init];
        _recommend.title =@"今日推荐";
        _recommend.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:_recommend animated:YES];
    }
    if (indexPath.section == 5) {
        UITableViewController *_luck = [[UITableViewController alloc]init];
        _luck.title =@"我的抽奖";
        _luck.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:_luck animated:YES];
    }

    
}

- (void)viewWillAppear:(BOOL)animated{
[self.navigationController.navigationBar.subviews objectAtIndex:0].alpha = 0;
}
//- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
//#warning Incomplete implementation, return the number of sections
//    return 0;
//}
//
//- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
//#warning Incomplete implementation, return the number of rows
//    return 0;
//}

/*
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#@"reuseIdentifier"#> forIndexPath:indexPath];
    
    // Configure the cell...
    
    return cell;
}
*/

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
